<!DOCTYPE html>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<c:set var="contextPath" value="${pageContext.request.contextPath}" />
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>查看待审核文章</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<meta content="width=device-width, initial-scale=1" name="viewport">
<link rel="stylesheet" type="text/css" href="${contextPath}/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="${contextPath}/css/bootstrap-theme.min.css" />
<link rel="stylesheet" type="text/css" href="${contextPath}/css/public.css">
<script type="text/javascript" src="${contextPath}/js/jquery.min.js"></script>
<script type="text/javascript" src="${contextPath}/js/bootstrap.min.js"></script>
<script type="text/javascript" src="${contextPath}/js/common.js"></script>
</head>
<body>
	<div class="container">
		<div class="panel panel-default">
			<div class="panel-heading">
				<span>文章状态: </span>
				<span class="label label-success">
					<c:choose>
					    <c:when test="${article.isGranted==1 }">
					 		通过
					    </c:when>
					    <c:otherwise>
					       	未通过
					    </c:otherwise>
					</c:choose>
				</span>&nbsp;&nbsp;
				<span class="label label-primary">
					<c:choose>
					    <c:when test="${article.isTop==1 }">
					 		置顶
					    </c:when>
					    <c:otherwise>
					       	未置顶
					    </c:otherwise>
					</c:choose>
				</span>&nbsp;&nbsp;
				<span class="label label-warning">
					<c:choose>
					    <c:when test="${article.isLocked==1 }">
					 		禁止评论
					    </c:when>
					    <c:otherwise>
					       	开启评论
					    </c:otherwise>
					</c:choose>
				</span>&nbsp;&nbsp;
				<span class="label label-danger">
					<c:choose>
					    <c:when test="${article.isDelete==1 }">
					 		删除
					    </c:when>
					    <c:otherwise>
					       	未删除
					    </c:otherwise>
					</c:choose>
				</span>
			</div>
			<div class="panel-body">
				<div id="titleArea" style="padding-top: 20px; padding-bottom: 20px; text-align: center;">
					<h1 >${article.articleTitle}</h1>
					<p style="font-size: 20px;color: #999;">作者： ${article.createUsername}&nbsp;&nbsp;&nbsp;&nbsp;时间：<fmt:formatDate value="${article.createTime}" pattern="yyyy年MM月dd日 ahh点mm分"/></p>
				</div>
				<div id="contentArea" style="margin-left: 20px;margin-right: 20px;">
					${article.articleContent}
				</div>
			</div>
		</div>
		<div style="text-align: center;">
			<c:choose>
				<c:when test="${article.isGranted==1 }">
					<button type="button" id="inspStatusBtn" class="btn btn-success">未通过审核</button>&nbsp;&nbsp;&nbsp;&nbsp;
				</c:when>
				<c:otherwise>
					<button type="button" id="inspStatusBtn" class="btn btn-success">通过审核</button>&nbsp;&nbsp;&nbsp;&nbsp;
				</c:otherwise>
			</c:choose>
			<c:choose>
				<c:when test="${article.isTop==1 }">
					<button type="button" id="topArticle" class="btn btn-primary">取消置顶</button>&nbsp;&nbsp;&nbsp;&nbsp;
				</c:when>
				<c:otherwise>
			      	<button type="button" id="topArticle" class="btn btn-primary">文章置顶</button>&nbsp;&nbsp;&nbsp;&nbsp;
			    </c:otherwise>
			</c:choose>
			<c:choose>
				<c:when test="${article.isLocked==1 }">
					<button type="button" id="lockArticle" class="btn btn-warning">开启评论</button>&nbsp;&nbsp;&nbsp;&nbsp;
				</c:when>
				<c:otherwise>
			      	<button type="button" id="lockArticle" class="btn btn-warning">禁止评论</button>&nbsp;&nbsp;&nbsp;&nbsp;
			    </c:otherwise>
			</c:choose>
			<c:choose>
				<c:when test="${article.isDelete==1 }">
					<button type="button" id="articleDelete" class="btn btn-danger">还原该文章</button>
				</c:when>
				<c:otherwise>
					<button type="button" id="articleDelete" class="btn btn-danger">删除该文章</button>
				</c:otherwise>
			</c:choose>
		</div>
		<input type="hidden" id="articleId" value="${article.id}">
	</div>
	
	<script type="text/javascript">
	<% 
		int userType = (Integer)session.getAttribute("usertype");
		if(userType != 5){
			%>
				$(function(){
					window.history.go(-1);
				});
			<%
		}
	%>
		var isGranted = ${article.isGranted};
		var isDelete = ${article.isDelete};
		var isTop = ${article.isTop};
		var islocked = ${article.isLocked};
		//修改审核状态
		$("#inspStatusBtn").click(function(){
			var articleId = $("#articleId").val();
			var confirmStr;
			var changeStatus;
			if(isGranted==0){
				confirmStr = "确定允许文章发布吗？";
				changeStatus = 1;
			}else{
				confirmStr = "确定修改为未审核状态吗？";
				changeStatus = 0;
			}
			var conWin = confirm(confirmStr);
			if (conWin) {
				$.ajax({
					type: 'POST',
					url: '${contextPath}/security/changeInspStatus',
					data: {"id": articleId, "isGranted":changeStatus},
					dataType: 'json',
					success: function (data) {
						alert(data.message);
						window.location.reload();
					}
				});
			}
		});
		
		$("#articleDelete").click(function(){
			var articleId = $("#articleId").val();
			var confirmStr;
			var changeStatus;
			if(isDelete==0){
				confirmStr = "确定要删除该文章吗？";
				changeStatus = 1;
			}else{
				confirmStr = "确定要还原该文章吗？";
				changeStatus = 0;
			}
			var conWin = confirm(confirmStr);
			if (conWin) {
				$.ajax({
					type: 'POST',
					url: '${contextPath}/security/changeDeleteStatus',
					data: {"id": articleId,"isDelete":changeStatus},
					dataType: 'json',
					success: function (data) {
						alert(data.message);
						window.location.reload();
					}
				});
			}
		});
		
		$("#topArticle").click(function(){
			var articleId = $("#articleId").val();
			var confirmStr;
			var changeStatus;
			if(isTop==0){
				confirmStr = "确定要置顶该文章吗？";
				changeStatus = 1;
			}else{
				confirmStr = "确定要取消文章置顶吗？";
				changeStatus = 0;
			}
			var conWin = confirm(confirmStr);
			if (conWin) {
				$.ajax({
					type: 'POST',
					url: '${contextPath}/security/changeTopStatus',
					data: {"id": articleId, "isTop":changeStatus},
					dataType: 'json',
					success: function (data) {
						alert(data.message);
						window.location.reload();
					}
				});
			}
		});
		
		$("#lockArticle").click(function(){
			var articleId = $("#articleId").val();
			var confirmStr;
			var changeStatus;
			if(islocked==0){
				confirmStr = "确定要禁止文章评论吗？";
				changeStatus = 1;
			}else{
				confirmStr = "确定要开启文章评论吗？？";
				changeStatus = 0;
			}
			var conWin = confirm(confirmStr);
			if (conWin) {
				$.ajax({
					type: 'POST',
					url: '${contextPath}/security/changeLockStatus',
					data: {"id": articleId, "isLock":changeStatus},
					dataType: 'json',
					success: function (data) {
						alert(data.message);
						window.location.reload();
					}
				});
			}
		});
	</script>
</body>
</html>
